<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div class="box">
        <p class="btn-red" onclick="c_red()"><span id="dian"></span></p>
        <p class="btn-green" onclick="c_green()"><span id="dian1"></span></p>
        <p class="btn-black" onclick="c_black()"><span id="dian2"></span></p>
    </div>
    <div class="box1">
        <table id="tab" cellspacing="0" cellpadding="0">
            <tr>
                <td>新闻</td>
                <td>娱乐</td>
                <td>体育</td>
                <td>电影</td>
                <td>音乐</td>
                <td>旅游</td>
            </tr>
        </table>
    </div>
</body>
<script>
    //将需要的元素全部获取回来
    var zsc = document.getElementById('tab')
    var zsc1 = document.getElementById('dian')
    var zsc2 = document.getElementById('dian1')
    var zsc3 = document.getElementById('dian2')
        //红色按钮
    function c_red() {
        document.body.bgColor = 'pink'
        tab.bgColor = 'red'
        zsc1.style.backgroundColor = 'white' //点红色按钮出现内部白盒
        zsc2.style.backgroundColor = '' //同时绿色按钮和黑色按钮内部盒子变空，依次类推
        zsc3.style.backgroundColor = ''
    }
    //绿色按钮
    function c_green() {
        document.body.bgColor = 'blue'
        tab.bgColor = 'green'
        zsc2.style.backgroundColor = 'white'
        zsc1.style.backgroundColor = ''
        zsc3.style.backgroundColor = ''
    }
    //黑色的按钮
    function c_black() {
        document.body.bgColor = '#ddd'
        tab.bgColor = 'black'
        zsc3.style.backgroundColor = 'white'
        zsc1.style.backgroundColor = ''
        zsc2.style.backgroundColor = ''
    }
</script>

</html>
<style>
    .box {
        width: 100px;
        height: 40px;
        margin: auto;
        text-align: center;
        display: flex;
    }
    
    span {
        width: 5px;
        height: 5px;
        display: block;
    }
    
    .btn-red {
        width: 20px;
        height: 20px;
        background-color: red;
        text-align: center;
        line-height: 20px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .btn-green {
        width: 20px;
        height: 20px;
        background: green;
        text-align: center;
        line-height: 20px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .btn-black {
        width: 20px;
        height: 20px;
        background: black;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .box1 table {
        margin: auto;
        width: 500px;
        border: 1px solid green;
        text-align: center;
        color: green;
    }
    
    .box1 table td {
        border: 1px solid green;
    }
</style>